package var.satisfiability;

import java.util.Iterator;

import tr.edu.ege.kipler.satisfiability.blocking.BlockingStrategy;
import tr.edu.ege.kipler.satisfiability.container.GenericABox;
import tr.edu.ege.kipler.satisfiability.container.Individual;
import tr.edu.ege.kipler.satisfiability.container.operational.IndividualNameManager;
import tr.edu.ege.kipler.syntax.Name;
import tr.edu.ege.kipler.syntax.concept.Concept;


public class StrongBlockingStrategy implements BlockingStrategy {

	public boolean isBlocked(GenericABox abox, Name individual) {
		boolean result = false;
		IndividualNameManager im = IndividualNameManager.getInstance();
		if (!im.isOldIndividual(individual.toString())) {
			for (Iterator<Individual> i = abox.individualIterator(); i.hasNext();) {
				Individual node = i.next();
				if (!im.isOldIndividual(node.getName().toString())
						&& im.isLessThan(node.getName().toString(), individual
								.toString())
						&& containsAll(node, abox.getIndividual(individual.toString()))) {
					result = true;
					break;
				}
			}
		}
		return result;
	}

	private boolean containsAll(Individual superset, Individual subset) {
		boolean result = true;
		for (Iterator<Concept> i = subset.conceptIterator(); i.hasNext();) {
			Concept concept = i.next();
			if (!superset.contains(concept)) {
				result = false;
			}
		}
		return result;
	}

}
